<?php
/**
 * Created by Silent Night.
 * Author: Silent Night
 * email: silentwolf_wp@163.com
 * Date: 2017/9/28
 * Time: 9:19
 */

namespace app\admin\controller;

use think\Controller;


class Agent extends Controller
{
    private $_model;
    private $title_field = [

    ];
    public $pagesize = 10;

    public function _initialize()
    {
        $this->_model = new \app\admin\model\Agent();
        $this->assign('LoginUserInfo', $this->LoginUserInfo);
        //获取当前用户的权限信息
        $this->assign('ruleLists', $this->LoginUserInfo['CurrPower']);
    }

    public function agentList(){
        $ser_key = trim(input("request.ser_key"));//auth
        $ser_val = trim(input("request.ser_val"));//auth
        $ser_ty = trim(input("request.ser_ty"));//auth
        $ser_stats = trim(input("request.ser_stats"));//auth
         if(!empty($ser_val)&&!empty($ser_key)){
             $pwhere[$ser_key] = array('like', '%' . $ser_val . '%');
         }
      
        
        $lists = $this->_model->lists($pwhere, $this->pagesize);
         
        $this->assign('lists', $lists);
         
        $this->assign('request', input("request."));
        return view('lists');
         
    }
    
    public function addData()
    {
    
        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {
            $data['uname']=trim(input("request.uname"));
            $data['pwd']=trim(input("request.pwd"));
            $data['nickname']=trim(input("request.nickname"));
            $data['money']=trim(input("request.money"));
            $data['stat']=trim(input("request.stat"));
            $data['acode']=trim(input("request.acode"));
            $data['ctime']=time();
            $res = $this->_model->add($data);
            if ($res) {
          
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }
    
    
        $title = "添加";
        $this->assign('title', $title);
        return view('addData');
    }

    
    public function delData()
    {
    
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }
        $w['id']=$id;
        $res = $this->_model->delData($w);
    
        if ($res) {
    
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
         
    }
    
    
    public function updateAc() {
        $id = trim(input("request.id"));
        $acid = trim(input("request.acid"));
        $cpModel = new \app\admin\model\ClassPhoto();
        $up['acid']=$acid;
        $cpres= $cpModel->updateData($up, $id);
        if ($cpres) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
         
    }
    
    public function updateStat() {
          $id = trim(input("request.id"));
          $stat = trim(input("request.stat"));
          $cpModel = new \app\admin\model\ClassPhoto();
          $up['stat']=$stat;
         $cpres= $cpModel->updateData($up, $id);
       if ($cpres) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
         
    }
    
   
    
}